var city = '泊头';

function loadXMLDoc() {
	var xmlhttp;
	if(window.XMLHttpRequest) {
		//  IE7+, Firefox, Chrome, Opera, Safari 浏览器执行代码
		xmlhttp = new XMLHttpRequest();
	} else {
		// IE6, IE5 浏览器执行代码
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange = function() {
		if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			var json = xmlhttp.responseText;
			json = JSON.parse(json);
			console.log(json);
			var list = document.querySelectorAll(".nav-main li");
			for(var i = 0; i < list.length; i++) {
				//时间
				list[i].children[0].innerHTML = json.daily_forecast[i].date.slice(8) + "日";
				//天气情况
				list[i].children[1].innerHTML = json.daily_forecast[i].cond.txt_n;
				//最高温度
				list[i].children[2].children[0].innerHTML = json.daily_forecast[i].tmp.max;
				//最低温度
				list[i].children[2].children[1].innerHTML = json.daily_forecast[i].tmp.min;
				//风向
				list[i].children[3].innerHTML = json.daily_forecast[i].wind.dir;
			}
			var list1 = document.querySelectorAll(".time li");
			for(var j = 0; j < list1.length; j++) {
				//console.log([j]);
				//时间
				list1[j].children[0].innerHTML = json.hourly_forecast[j].date.slice(11,13) + "时";
				//温度
				list1[j].children[1].children[0].innerHTML = json.hourly_forecast[j].tmp;
				//风向
				list1[j].children[2].innerHTML = json.hourly_forecast[j].wind.dir;
				//几级风
				list1[j].children[3].innerHTML = json.hourly_forecast[j].wind.sc + '级';
				//console.log(json.hourly_forecast[j].date.slice(11,13));
			}
			var life = document.querySelectorAll(".life ul li .life-right");
			for(var k = 0; k < life.length; k++) {
				//console.log(life[k]);
				life[0].children[0].innerHTML = json.suggestion.uv.brf;
				life[0].children[1].innerHTML = json.suggestion.uv.txt;
				life[1].children[0].innerHTML = json.suggestion.sport.brf;
				life[1].children[1].innerHTML = json.suggestion.sport.txt;
				life[2].children[0].innerHTML = json.suggestion.flu.brf;
				life[2].children[1].innerHTML = json.suggestion.flu.txt;
				life[3].children[0].innerHTML = json.suggestion.drsg.brf;
				life[3].children[1].innerHTML = json.suggestion.drsg.txt;
				life[4].children[0].innerHTML = json.suggestion.cw.brf;
				life[4].children[1].innerHTML = json.suggestion.cw.txt;
				life[5].children[0].innerHTML = json.suggestion.air.brf;
				life[5].children[1].innerHTML = json.suggestion.air.txt;
			}
		}
	}
	xmlhttp.open("GET", "https://bird.ioliu.cn/weather?city=" + city, true);
	xmlhttp.send();
}
loadXMLDoc();
document.querySelector(".ipt").addEventListener('change', function() {
	console.log(this.value);
	city = this.value;
	loadXMLDoc();
})